import 'package:demo_app_video/page/personal/personal.dart';
import 'package:demo_app_video/page/signs/signs.dart';
import 'package:demo_app_video/page/video_card/video_card.dart';
import 'package:demo_app_video/page/videos/video.dart';
import 'package:flutter/material.dart';
import 'package:flutter_adcontent/flutter_adcontent.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class HomeMainPage extends StatefulWidget {
  const HomeMainPage({Key? key}) : super(key: key);

  @override
  State<HomeMainPage> createState() => _HomeMainPageState();
}

class _HomeMainPageState extends State<HomeMainPage> {
  PageController _controller = PageController(initialPage: 1);

  late ProVideoController? _videoController;

  int index = 1;

  List<Widget> pages = [];

  @override
  void initState() {
    _videoController = ProVideoController();

    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, designSize: const Size(360, 780));
    return Scaffold(
      body: PageView(
        children: [
          VideoCardPage(
            controller: _videoController,
          ),
          VideoPage(),
          PersonalPage()
        ],
        controller: _controller,
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: Container(
        padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
        width: 360.w,
        height: 50.h + MediaQuery.of(context).padding.bottom,
        decoration: BoxDecoration(color: Color(0xffFFFFFF)),
        child: Row(
          children: [
            buildItem(
              tip: '推荐',
              img_path: 'images/icons/tuijian.png',
              type_index: 0,
            ),
            buildItem(
              tip: '剧场',
              img_path: 'images/icons/video.png',
              type_index: 1,
            ),
            // buildItem(
            //   tip: '福利',
            //   img_path: 'images/icons/sign.png',
            //   type_index: 2,
            // ),
            buildItem(
              tip: '我的',
              img_path: 'images/icons/personal.png',
              type_index: 2,
            ),
          ],
        ),
      ),
    );
  }

  buildItem({img_path, tip, type_index}) {
    return Expanded(
        child: InkWell(
      onTap: () {
        if (index != type_index) {
          index = type_index;
          if (index != 0) {
            _videoController!.pause();
          } else {
            _videoController!.resume();
          }
          setState(() {});
          _controller.jumpToPage(index);
        }
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          type_index == index
              ? Image.asset(
                  '${img_path}',
                  width: 22.w,
                  height: 22.w,
                  color: Color.fromRGBO(249, 142, 75, 1),
                )
              : Image.asset(
                  '${img_path}',
                  width: 22.w,
                  height: 22.w,
                ),
          Text(
            '${tip}',
            style: TextStyle(
                color: type_index == index
                    ? Color.fromRGBO(249, 142, 75, 1)
                    : Color(0xff8E8E93),
                fontSize: 10.sp),
          )
        ],
      ),
    ));
  }
}
